home *** CD-ROM | disk | FTP | other *** search
-
- #include "RadarView.h"
- #include <fp.h>
- #include "BaseStation.h"
-
- const UInt32 kLocDotRadius = 10;
- const UInt32 kTotalPhosphorSteps = 16;
- const UInt32 kDegreesPerStep = 2;
- const double kPi = 3.14159;
-
- #define DRAW_INTERSECT_POINTS 0
-
- static BaseStationList sBaseStationList;
-
- RadarView::RadarView(
- LStream * inStream)
- : LOffscreenView(inStream),
- LPeriodical(),
- mRadarMapPict(NULL),
- mLastLocationUpdateTime(0),
- mLastSweepUpdateTime(0)
- {
- StartIdling();
-
- mCurrentLocation.h = 0;
- mCurrentLocation.v = 0;
- mPreviousLocation.h = 0;
- mPreviousLocation.v = 0;
-
- mSweepAngle = 0.0;
- }
-
- RadarView::~RadarView()
- {
- }
-
-
- void
- RadarView::FinishCreateSelf()
- {
- Rect bounds;
- CalcLocalFrameRect(bounds);
- mCenterOfWindow.h = bounds.right / 2;
- mCenterOfWindow.v = bounds.bottom / 2;
- }
-
-
- void
- RadarView::DrawSelf()
- {
- LOffscreenView::DrawSelf();
-
- // Draw the PICT first
- if (mRadarMapPict == NULL)
- mRadarMapPict = ::GetPicture(128);
-
- if (mRadarMapPict != NULL)
- {
- Rect boundingRect;
-
- boundingRect = mRadarMapPict[0]->picFrame;
-
- ::DrawPicture(mRadarMapPict, &boundingRect);
-
- RGBColor redRGBColor = {0xC000, 0x0000, 0x0000};
-
- ::RGBForeColor(&redRGBColor);
-
- ::SetRect(&boundingRect, mCurrentLocation.h - kLocDotRadius,
- mCurrentLocation.v - kLocDotRadius,
- mCurrentLocation.h + kLocDotRadius,
- mCurrentLocation.v + kLocDotRadius);
-
- ::PaintOval(&boundingRect);
-
- ::MoveTo(mCurrentLocation.h + kLocDotRadius, mCurrentLocation.v - kLocDotRadius);
- ::DrawString("\pYou Are Here");
-
- Rect bounds;
- CalcLocalFrameRect(bounds);
-
- ::InsetRect(&bounds, -1000, -1000);
-
- // Draw the trailing phosphors
- SInt32 curAngleInDegrees = mSweepAngle / kPi * 180 + 90 - kDegreesPerStep * kTotalPhosphorSteps;
- for (UInt32 phosphorStep = 0; phosphorStep < kTotalPhosphorSteps; phosphorStep++)
- {
- if (curAngleInDegrees >= 360)
- curAngleInDegrees -= 360;
- RGBColor notGreenColor = {phosphorStep * 0x8000 / kTotalPhosphorSteps,
- 0x0000,
- phosphorStep * 0x8000 / kTotalPhosphorSteps};
- ::RGBForeColor(¬GreenColor);
- ::PenMode(subPin);
- ::PaintArc(&bounds, curAngleInDegrees, kDegreesPerStep);
-
- curAngleInDegrees += kDegreesPerStep;
- }
-
- // Draw the sweeping Radar line
- ::PenSize(2, 2);
- ::PenMode(srcCopy);
-
- curAngleInDegrees -= 90.0;
- ::MoveTo(mCenterOfWindow.h, mCenterOfWindow.v);
- ::ForeColor(greenColor);
- ::Line(4000.0 * cos((double)curAngleInDegrees * kPi / 180.0), 4000.0 * sin((double)curAngleInDegrees * kPi / 180.0));
-
- ::PenNormal();
- ::ForeColor(blackColor);
-
- // Display circles to show strength
- RGBColor grayColor = {0x2000, 0x2000, 0x2000};
- ::RGBForeColor(&grayColor);
- ::PenMode(subPin);
-
- for (UInt32 baseIndex = 0; baseIndex < sBaseStationList.fBaseCount; baseIndex++)
- {
- if (sBaseStationList.fBases[baseIndex].fStrongSignal)
- {
- Rect radiusBox;
-
- ::SetRect(&radiusBox,
- sBaseStationList.fBases[baseIndex].fX - sBaseStationList.fBases[baseIndex].fR,
- sBaseStationList.fBases[baseIndex].fY - sBaseStationList.fBases[baseIndex].fR,
- sBaseStationList.fBases[baseIndex].fX + sBaseStationList.fBases[baseIndex].fR,
- sBaseStationList.fBases[baseIndex].fY + sBaseStationList.fBases[baseIndex].fR);
-
- ::PaintOval(&radiusBox);
- }
- }
-
- #if DRAW_INTERSECT_POINTS
- for (UInt32 sectPoint = 0; sectPoint < 3; sectPoint++)
- {
- Rect sampleBox;
-
- ::SetRect(&sampleBox,
- sBaseStationList.fSectPoints[sectPoint].fPoint1.fX - 2,
- sBaseStationList.fSectPoints[sectPoint].fPoint1.fY - 2,
- sBaseStationList.fSectPoints[sectPoint].fPoint1.fX + 2,
- sBaseStationList.fSectPoints[sectPoint].fPoint1.fY + 2);
-
- ::PaintOval(&sampleBox);
-
- ::SetRect(&sampleBox,
- sBaseStationList.fSectPoints[sectPoint].fPoint2.fX - 2,
- sBaseStationList.fSectPoints[sectPoint].fPoint2.fY - 2,
- sBaseStationList.fSectPoints[sectPoint].fPoint2.fX + 2,
- sBaseStationList.fSectPoints[sectPoint].fPoint2.fY + 2);
-
- ::PaintOval(&sampleBox);
- }
- #endif
- }
- }
-
- void
- RadarView::SpendTime(
- const EventRecord & inMacEvent)
- {
- // Has enough time passed yet? If so, recalculate and
- // refresh the screen.
- if (inMacEvent.when > mLastLocationUpdateTime + 60)
- {
- UpdateLocation();
- mLastLocationUpdateTime = inMacEvent.when;
- }
-
- if (inMacEvent.when != mLastSweepUpdateTime)
- {
- mSweepAngle += kPi / 64.0;
- if (mSweepAngle > 2 * kPi)
- mSweepAngle -= 2 * kPi;
-
- mLastSweepUpdateTime = inMacEvent.when;
- Refresh();
- }
- }
-
-
- void
- RadarView::UpdateLocation()
- {
- sBaseStationList.IdleBases();
-
- Point prev = mPreviousLocation;
-
- mPreviousLocation.h = (SInt16)sBaseStationList.fX;
- mPreviousLocation.v = (SInt16)sBaseStationList.fY;
-
- // Average previous and current
- mCurrentLocation.h = (mPreviousLocation.h + prev.h) / 2;
- mCurrentLocation.v = (mPreviousLocation.v + prev.v) / 2;
-
- }
-
-
-
-
-